package com.sz.pc.controller.excel;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.sz.pc.entity.model.ResultData;
import com.sz.pc.entity.model.ResultDataEnum;
import com.sz.pc.service.interfs.excel.IInvestExcelService;
import com.sz.pc.utils.excel.ExcelUtil;


@Controller
@RequestMapping("/import/")
public class ImportController {
	
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Resource
	private IInvestExcelService investExcelService; 
	
	@GetMapping("importInvest")
	public String importSxUI(){
		return "import/importInvest";
	}
	
	@PostMapping("importInvest")
	@ResponseBody
    public Object importSx(HttpServletRequest request) {
        MultipartFile file = ExcelUtil.getFile(request);
		if (file != null) {
			try 
			{
				return investExcelService.importInvestExcel(file);
			} 
			catch (Exception e) 
			{
				logger.error("导入投资额度异常");
				return new ResultData(ResultDataEnum.SERVER_ERROR.getCode(),e.getMessage(),null);
			}
		}
		return new ResultData(ResultDataEnum.PARAMS_ERROR.getCode(),"没有上传文件",null);
    }
	
	

}